import {InputNumber, Modal, Icon} from 'antd';
import isEmpty from 'lodash/isEmpty';
import isArray from 'lodash/isArray'
import {WeaDatePicker,WeaTimePicker} from "ecCom"
import equals from 'deep-equal'

class Main extends React.Component {
  constructor(props){
    super(props)
    this.state={
      dateValue: '',
      timeValue: ''
    }
    if (!isEmpty(props.value)) {
      if (props.value[0]) this.state.dateValue = props.value[0];
      if (props.value[1]) this.state.timeValue = props.value[1];
    }
  }
  componentWillReceiveProps(nextProps){
    if (!equals(this.props.value,nextProps.value)) {
      let dateValue = '', timeValue = '';
      if (!isEmpty(nextProps.value)) {
          dateValue = nextProps.value[0];
          timeValue = nextProps.value[1];
      }
      this.setState({dateValue, timeValue});
    }
  }
  onChangeDate(value) {
    this.setState({dateValue: value});
    const {timeValue = ''} = this.state;
    this.props.onChange && this.props.onChange([value, timeValue]);
  }
  onChangeTime(value) {
    this.setState({timeValue: value});
    const {dateValue = ''} = this.state;
    this.props.onChange && this.props.onChange([dateValue, value]);
  }
  render(){
    const {dateValue, timeValue, } = this.state;
    const {viewAttr,otherParams,startValue="",endValue="",isTimeShow='1',type,domkey}=this.props;
    let name = domkey&&domkey[0];
    let timename = '';
    if(name==='begindate'){
      timename ='begintime';
    }else if(name==='enddate'){
      timename ='endtime';
    }else if(name==='actualbegindate'){
      timename ='actualbegintime';
    }else if(name==='actualenddate'){
      timename ='actualendtime';
    }
    return(
      <div className='prj-date-time'>
            <span>
                <WeaDatePicker ecId={`${this && this.props && this.props.ecId || ''}_WeaDatePicker@yzs4u6`} name={name} startValue={startValue} endValue={endValue}  viewAttr={viewAttr} formatPattern={2} value={dateValue} {...otherParams} onChange={this.onChangeDate.bind(this)}/>
            </span>
            <span style={{marginLeft:10}}>
                <WeaTimePicker ecId={`${this && this.props && this.props.ecId || ''}_WeaTimePicker@ywlbuo`} name={timename} style={{display:isTimeShow=='1'?'':'none'}} viewAttr={viewAttr} formatPattern={3}  value={isTimeShow=='1'?timeValue:type=='start'?'00:00':'23:59'} {...otherParams} onChange={this.onChangeTime.bind(this)} />
            </span>
      </div>
     );
  }
}

export  default Main;